package cn.itcast.web.controller;

import cn.itcast.domain.system.User;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public abstract class BaseController {

    // 注入request对象
    @Autowired
    protected HttpServletRequest request;
    @Autowired(required = false)
    protected HttpServletResponse response;
    @Autowired
    protected HttpSession httpSession;

    /**
     * 返回当前登陆用户
     */
    public User getLoginUser(){
        return (User) httpSession.getAttribute("loginUser");
    }

    /**
     * 从登陆用户中获取所属企业id (先写死)
     * @return
     */
    public String getLoginCompanyId(){
        return getLoginUser().getCompanyId();
    }

    /**
     * 从登陆用户中获取所属企业id (先写死)
     * @return
     */
    public String getLoginCompanyName(){
        return getLoginUser().getCompanyName();
    }
}
